home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sources / xless / xless141.z / xless141 / xless-1.4.1 / popup.c < prev    next >
C/C++ Source or Header  |  1993-05-05  |  8KB  |  252 lines

  1. /*
  2.  * Copyright 1989 Massachusetts Institute of Technology
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of M.I.T. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  M.I.T. makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  15.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  16.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  18.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  19.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20.  *
  21.  * Author: Carlo Lisa
  22.  *       MIT Project Athena
  23.  *       carlo@athena.mit.edu
  24.  *
  25.  * $Header: /usr/sww/share/src/X11R5/local/clients/xless-1.4/RCS/popup.c,v 1.14 1993/02/26 01:12:17 dglo Exp dglo $
  26.  */
  27.  
  28. #include "xless.h"
  29.  
  30. /* stole this chunk from xdm/dm.c */
  31. #if defined(USE_PROTOTYPES) || defined(__STDC__)
  32. #include <stdarg.h>
  33. #define Va_start(a,b)    va_start(a,b)
  34. #else
  35. #include <varargs.h>
  36. #define Va_start(a,b)    va_start(a)
  37. #endif
  38.  
  39. /*
  40.  *    Function Name: DialogBox
  41.  *    Description:   This function creates a single dialog box.
  42.  *    Arguments:  top        parent widget;
  43.  *            conf_func    confirm function (callback);
  44.  *            c_data    callback data (for conf_func);
  45.  *            label    label for the dialog box;
  46.  *            selection     user's input (back).
  47.  *    Returns:    popup    the dialogbox widget id.
  48.  */
  49.  
  50. Widget
  51. DialogBox(top, conf_func, c_data, label, conflab, selection)
  52. Widget top;
  53. XtCallbackProc conf_func;
  54. XtPointer c_data;
  55. const char *label;
  56. const char *conflab;
  57. char *selection;
  58. {
  59.   static XtActionsRec dbactions[2];
  60.   static String myreturn = "#override <Key>Return:   set() notify() unset()\n";
  61.   XtAccelerators accel;
  62.   static int init = 0;
  63.   Widget popup, form, lbl, input, confirm, cancel;
  64.   Arg args[15];
  65.   Cardinal i;
  66.   XtCallbackRec callback[2];
  67.  
  68.   dbactions[0].string = "Nothing";
  69.   dbactions[0].proc = (XtActionProc)NULL;
  70.  
  71.   if (!init) {
  72.     XtAddActions(dbactions, XtNumber(dbactions));
  73.     init = 1;
  74.   }
  75.  
  76.   accel = XtParseAcceleratorTable(myreturn);
  77.  
  78.   callback[1].callback = NULL;
  79.   callback[1].closure = (XtPointer)NULL;
  80.  
  81.   i = 0;
  82.   XtSetArg(args[0], XtNallowShellResize, True); i++;
  83.   popup = XtCreatePopupShell("popup", transientShellWidgetClass, top, args, i);
  84.  
  85.   i = 0;
  86.   form = XtCreateManagedWidget("form", formWidgetClass, popup, args, i);
  87.  
  88.   i = 0;
  89.   XtSetArg(args[i], XtNjustify, XtJustifyLeft); i++;
  90.   XtSetArg(args[i], XtNborderWidth, 0); i++;
  91.   XtSetArg(args[i], XtNlabel, label); i++;
  92.   XtSetArg(args[i], XtNfont, labelfont); i++;
  93.   XtSetArg(args[i], XtNright, XtChainLeft); i++;
  94.   XtSetArg(args[i], XtNleft, XtChainLeft); i++;
  95.   lbl = XtCreateManagedWidget("label", labelWidgetClass, form, args, i);
  96.   i = 0;
  97.   XtSetArg(args[i], XtNfont, textfont); i++;
  98.   XtSetArg(args[i], XtNeditType, XawtextEdit); i++;
  99.   XtSetArg(args[i], XtNstring, selection); i++;
  100.   XtSetArg(args[i], XtNlength, MAX_INPUT); i++;
  101.   XtSetArg(args[i], XtNwidth, DEF_INPUT_W); i++;
  102.   XtSetArg(args[i], XtNresizable, True); i++;
  103. #ifdef X11R4
  104.   XtSetArg(args[i], XtNtextOptions, resizeWidth); i++;
  105. #endif
  106.   XtSetArg(args[i], XtNvertDistance, 0); i++;
  107.   XtSetArg(args[i], XtNfromVert, lbl); i++;
  108.   XtSetArg(args[i], XtNfromHoriz, NULL); i++;
  109.   XtSetArg(args[i], XtNright, XtChainLeft); i++;
  110.   XtSetArg(args[i], XtNleft, XtChainLeft); i++;
  111.   XtSetArg(args[i], XtNuseStringInPlace, True); i++;
  112.   input = XtCreateManagedWidget("input", asciiTextWidgetClass, form, args, i);
  113.   XtSetKeyboardFocus(form, input);
  114.  
  115.   i = 0;
  116.   XtSetArg(args[i], XtNfont, buttonfont); i++;
  117.   XtSetArg(args[i], XtNcursor, dialogcur); i++;
  118.   XtSetArg(args[i], XtNwidth, BUTTONWIDTH); i++;
  119.   XtSetArg(args[i], XtNvertDistance, 5); i++;
  120.   XtSetArg(args[i], XtNfromVert, input); i++;
  121.   XtSetArg(args[i], XtNfromHoriz, NULL); i++;
  122.   XtSetArg(args[i], XtNright, XtChainLeft); i++;
  123.   XtSetArg(args[i], XtNleft, XtChainLeft); i++;
  124.   callback[0].callback = conf_func;
  125.   callback[0].closure = c_data;
  126.   XtSetArg(args[i], XtNcallback, callback); i++;
  127.   XtSetArg(args[i], XtNaccelerators, accel); i++;
  128.   confirm = XtCreateManagedWidget(conflab, commandWidgetClass, form, args, i);
  129.  
  130.   i = 0;
  131.   XtSetArg(args[i], XtNfont, buttonfont); i++;
  132.   XtSetArg(args[i], XtNcursor, dialogcur); i++;
  133.   XtSetArg(args[i], XtNwidth, BUTTONWIDTH); i++;
  134.   XtSetArg(args[i], XtNvertDistance, 5); i++;
  135.   XtSetArg(args[i], XtNhorizDistance, 2); i++;
  136.   XtSetArg(args[i], XtNfromVert, input); i++;
  137.   XtSetArg(args[i], XtNfromHoriz, confirm); i++;
  138.   XtSetArg(args[i], XtNright, XtChainLeft); i++;
  139.   XtSetArg(args[i], XtNleft, XtChainLeft); i++;
  140.   callback[0].callback = Cancel;
  141.   callback[0].closure = (XtPointer)popup;
  142.   XtSetArg(args[i], XtNcallback, callback); i++;
  143.   cancel = XtCreateManagedWidget("Cancel", commandWidgetClass, form,
  144.                  args, i);
  145.  
  146.   XtInstallAccelerators(input, confirm);
  147.  
  148.   return(popup);
  149. }
  150.  
  151. static void
  152. popdownBox(widget, closure, callData)
  153. Widget widget;
  154. XtPointer closure;
  155. XtPointer callData;
  156. {
  157.   XtPopdown((Widget)closure);
  158. }
  159.  
  160. /*
  161.  *    Function Name:    MessageBox
  162.  *    Description:    This function creates the message dialog box.
  163.  *    Arguments:  top        widget to use as message box parent
  164.  *            msg        message to display
  165.  *            btnlabel    label on next button
  166.  *            btnproc    callback executed when next button is pressed
  167.  *    Returns:    widget    id of the message box.
  168.  */
  169.  
  170. Widget
  171. #if defined(USE_PROTOTYPES) || defined(__STDC__)
  172. MessageBox(Widget top, const char *msg, ...)
  173. #else
  174. MessageBox(top, msg, va_alist)
  175. Widget *top;
  176. const char *msg;
  177. va_dcl
  178. #endif
  179. {
  180.   extern XtAppContext context;
  181.   Widget msg_pop, form, msg_label, button;
  182.   Arg args[15];
  183.   Cardinal i;
  184.   XtCallbackRec callback[2];
  185.   static String myreturn = "#override <Key>Return: set() notify() unset()\n";
  186.   XtAccelerators accel;
  187.   const char *btntext;
  188.   XtCallbackProc btnproc;
  189.   va_list vap;
  190.  
  191.   /* can't popup a messagebox if widgets haven't been realized yet... */
  192.   if (!XtIsRealized(top)) {
  193.     XtAppWarning(context, msg);
  194.     return 0;
  195.   }
  196.  
  197.   accel = XtParseAcceleratorTable(myreturn);
  198.  
  199.   callback[1].callback = (XtCallbackProc) NULL;
  200.   callback[1].closure = (XtPointer) NULL;
  201.  
  202.   i = 0;
  203.   XtSetArg(args[0], XtNallowShellResize, True); i++;
  204.   msg_pop = XtCreatePopupShell("msg_pop", transientShellWidgetClass, top,
  205.                    args, i);
  206.  
  207.   i = 0;
  208.   XtSetArg(args[0], XtNallowShellResize, True); i++;
  209.   form = XtCreateManagedWidget("form", formWidgetClass, msg_pop, args, i);
  210.  
  211.   i = 0;
  212.   XtSetArg(args[0], XtNallowShellResize, True); i++;
  213.   XtSetArg(args[i], XtNjustify, XtJustifyLeft); i++;
  214.   XtSetArg(args[i], XtNborderWidth, 0); i++;
  215.   XtSetArg(args[i], XtNlabel, msg); i++;
  216.   XtSetArg(args[i], XtNfont, labelfont); i++;
  217.   msg_label = XtCreateManagedWidget("message", labelWidgetClass, form,
  218.                     args, i);
  219.  
  220.   Va_start(vap, msg);
  221.   btntext = (const char *)va_arg(vap, const char *);
  222.  
  223.   button = 0;
  224.   while (btntext) {
  225.     btnproc = (XtCallbackProc )va_arg(vap, XtCallbackProc);
  226.  
  227.     i = 0;
  228.     XtSetArg(args[i], XtNfont, buttonfont); i++;
  229.     XtSetArg(args[i], XtNcursor, dialogcur); i++;
  230.     XtSetArg(args[i], XtNwidth, BUTTONWIDTH); i++;
  231.     XtSetArg(args[i], XtNvertDistance, 1); i++;
  232.     XtSetArg(args[i], XtNfromVert, msg_label); i++;
  233.     XtSetArg(args[i], XtNfromHoriz, button); i++;
  234.     XtSetArg(args[i], XtNright, XtChainRight); i++;
  235.     XtSetArg(args[i], XtNleft, XtChainRight); i++;
  236.     if (btnproc)
  237.       callback[0].callback = btnproc;
  238.     else
  239.       callback[0].callback = popdownBox;
  240.     callback[0].closure = (XtPointer)msg_pop;
  241.     XtSetArg(args[i], XtNcallback, callback); i++;
  242.     XtSetArg(args[i], XtNaccelerators, accel); i++;
  243.     button = XtCreateManagedWidget(btntext, commandWidgetClass, form, args, i);
  244.  
  245.     XtInstallAccelerators(form, button);
  246.  
  247.     btntext = (const char *)va_arg(vap, const char *);
  248.   }
  249.  
  250.   return(msg_pop);
  251. }
  252.